{{ header }}{{ column_left }}
<div id="content">
  <div class="page-header">
    <div class="container-fluid">
      <div class="float-right">
        <button type="submit" form="form-customer" data-toggle="tooltip" title="{{ button_save }}" class="btn btn-primary"><i class="fas fa-save"></i></button>
        <a href="{{ cancel }}" data-toggle="tooltip" title="{{ button_cancel }}" class="btn btn-light"><i class="fas fa-reply"></i></a></div>
      <h1>{{ heading_title }}</h1>
      <ol class="breadcrumb">
        {% for breadcrumb in breadcrumbs %}
          <li class="breadcrumb-item"><a href="{{ breadcrumb.href }}">{{ breadcrumb.text }}</a></li>
        {% endfor %}
      </ol>
    </div>
  </div>
  <div class="container-fluid">
    {% if error_warning %}
      <div class="alert alert-danger alert-dismissible"><i class="fas fa-exclamation-circle"></i> {{ error_warning }}
        <button type="button" class="close" data-dismiss="alert">&times;</button>
      </div>
    {% endif %}
    <div class="card">
      <div class="card-header"><i class="fas fa-pencil-alt"></i> {{ text_form }}</div>
      <div class="card-body">
        <form action="{{ action }}" method="post" enctype="multipart/form-data" id="form-customer">
          <ul class="nav nav-tabs">
            <li class="nav-item"><a href="#tab-general" data-toggle="tab" class="nav-link active">{{ tab_general }}</a></li>
            {% if customer_id %}
              <li class="nav-item"><a href="#tab-history" data-toggle="tab" class="nav-link">{{ tab_history }}</a></li>
              <li class="nav-item"><a href="#tab-transaction" data-toggle="tab" class="nav-link">{{ tab_transaction }}</a></li>
              <li class="nav-item"><a href="#tab-report" data-toggle="tab" class="nav-link">{{ tab_report }}</a></li>
            {% endif %}
          </ul>
          <div class="tab-content">
            <div class="tab-pane active" id="tab-general">
              <fieldset>
                <legend>{{ text_affiliate }}</legend>
                <div class="form-group row required">
                  <label class="col-sm-2 col-form-label" for="input-customer">{{ entry_customer }}</label>
                  <div class="col-sm-10">
                    {% if not customer_id %}
                      <input type="text" name="customer" value="{{ customer }}" placeholder="{{ entry_customer }}" id="input-customer" class="form-control"/>
                    {% else %}
                      <input type="text" name="customer" value="{{ customer }}" placeholder="{{ entry_customer }}" id="input-customer" class="form-control" disabled/>
                    {% endif %}
                    <input type="hidden" name="customer_id" value="{{ customer_id }}"/> <input type="hidden" name="customer_group_id" value="{{ customer_group_id }}"/>
                  </div>
                </div>
                <div class="form-group row">
                  <label class="col-sm-2 col-form-label" for="input-company">{{ entry_company }}</label>
                  <div class="col-sm-10">
                    <input type="text" name="company" value="{{ company }}" placeholder="{{ entry_company }}" id="input-company" class="form-control"/>
                  </div>
                </div>
                <div class="form-group row">
                  <label class="col-sm-2 col-form-label" for="input-website">{{ entry_website }}</label>
                  <div class="col-sm-10">
                    <input type="text" name="website" value="{{ website }}" placeholder="{{ entry_website }}" id="input-website" class="form-control"/>
                  </div>
                </div>
                <div class="form-group row">
                  <label class="col-sm-2 col-form-label" for="input-tracking">{{ entry_tracking }}</label>
                  <div class="col-sm-10">
                    <input type="text" name="tracking" value="{{ tracking }}" placeholder="{{ entry_tracking }}" id="input-tracking" class="form-control"/>
                    <small class="form-text text-muted">{{ help_tracking }}</small>
                    {% if error_tracking %}
                      <div class="invalid-tooltip">{{ error_tracking }}</div>
                    {% endif %}
                  </div>
                </div>
                <div class="form-group row">
                  <label class="col-sm-2 col-form-label" for="input-commission">{{ entry_commission }}</label>
                  <div class="col-sm-10">
                    <input type="text" name="commission" value="{{ commission }}" placeholder="{{ entry_commission }}" id="input-commission" class="form-control"/>
                    <small class="form-text text-muted">{{ help_commission }}</small>
                  </div>
                </div>
                {% for custom_field in custom_fields %}
                  {% if custom_field.location == 'affiliate' %}
                    {% if custom_field.type == 'select' %}
                      <div class="form-group row custom-field custom-field{{ custom_field.custom_field_id }}" data-sort="{{ custom_field.sort_order }}">
                        <label class="col-sm-2 col-form-label" for="input-custom-field{{ custom_field.custom_field_id }}">{{ custom_field.name }}</label>
                        <div class="col-sm-10">
                          <select name="custom_field[{{ custom_field.custom_field_id }}]" id="input-custom-field{{ custom_field.custom_field_id }}" class="form-control">
                            <option value="">{{ text_select }}</option>
                            {% for custom_field_value in custom_field.custom_field_value %}
                              {% if affiliate_custom_field[custom_field.custom_field_id] and custom_field_value.custom_field_value_id == affiliate_custom_field[custom_field.custom_field_id] %}
                                <option value="{{ custom_field_value.custom_field_value_id }}" selected="selected">{{ custom_field_value.name }}</option>
                              {% else %}
                                <option value="{{ custom_field_value.custom_field_value_id }}">{{ custom_field_value.name }}</option>
                              {% endif %}
                            {% endfor %}
                          </select>
                          {% if error_custom_field[custom_field.custom_field_id] %}
                            <div class="invalid-tooltip">{{ error_custom_field[custom_field.custom_field_id] }}</div>
                          {% endif %}</div>
                      </div>
                    {% endif %}
                    {% if custom_field.type == 'radio' %}
                      <div class="form-group row custom-field custom-field{{ custom_field.custom_field_id }}" data-sort="{{ custom_field.sort_order }}">
                        <label class="col-sm-2 col-form-label">{{ custom_field.name }}</label>
                        <div class="col-sm-10">
                          <div>{% for custom_field_value in custom_field.custom_field_value %}
                              <label class="form-check">
                              {% if affiliate_custom_field[custom_field.custom_field_id] and custom_field_value.custom_field_value_id == affiliate_custom_field[custom_field.custom_field_id] %}
                                <input type="radio" name="custom_field[{{ custom_field.custom_field_id }}]" value="{{ custom_field_value.custom_field_value_id }}" checked="checked" class="form-check-input"/>
                                {{ custom_field_value.name }}</label>
                              {% else %}
                                <input type="radio" name="custom_field[{{ custom_field.custom_field_id }}]" value="{{ custom_field_value.custom_field_value_id }}" class="form-check-input"/>
                                {{ custom_field_value.name }}
                              {% endif %}
                              </label>
                            {% endfor %}
                          </div>
                          {% if error_custom_field[custom_field.custom_field_id] %}
                            <div class="invalid-tooltip">{{ error_custom_field[custom_field.custom_field_id] }}</div>
                          {% endif %}</div>
                      </div>
                    {% endif %}
                    {% if custom_field.type == 'checkbox' %}
                      <div class="form-group row custom-field custom-field{{ custom_field.custom_field_id }}" data-sort="{{ custom_field.sort_order }}">
                        <label class="col-sm-2 col-form-label">{{ custom_field.name }}</label>
                        <div class="col-sm-10">
                          <div>
                            {% for custom_field_value in custom_field.custom_field_value %}
                              <label class="form-check">
                              {% if affiliate_custom_field[custom_field.custom_field_id] and custom_field_value.custom_field_value_id in affiliate_custom_field[custom_field.custom_field_id] %}
                                <input type="checkbox" name="custom_field[{{ custom_field.custom_field_id }}][]" value="{{ custom_field_value.custom_field_value_id }}" checked="checked" class="form-check-input"/>
                                {{ custom_field_value.name }}</label>
                              {% else %}
                                <input type="checkbox" name="custom_field[{{ custom_field.custom_field_id }}][]" value="{{ custom_field_value.custom_field_value_id }}" class="form-check-input"/>
                                {{ custom_field_value.name }}
                              {% endif %}
                              </label>
                            {% endfor %}
                          </div>
                          {% if error_custom_field[custom_field.custom_field_id] %}
                            <div class="invalid-tooltip">{{ error_custom_field[custom_field.custom_field_id] }}</div>
                          {% endif %}</div>
                      </div>
                    {% endif %}
                    {% if custom_field.type == 'text' %}
                      <div class="form-group row custom-field custom-field{{ custom_field.custom_field_id }}" data-sort="{{ custom_field.sort_order }}">
                        <label class="col-sm-2 col-form-label" for="input-custom-field{{ custom_field.custom_field_id }}">{{ custom_field.name }}</label>
                        <div class="col-sm-10">
                          <input type="text" name="custom_field[{{ custom_field.custom_field_id }}]" value="{{ affiliate_custom_field[custom_field.custom_field_id] ? affiliate_custom_field[custom_field.custom_field_id] : custom_field.value }}" placeholder="{{ custom_field.name }}" id="input-custom-field{{ custom_field.custom_field_id }}" class="form-control"/>
                          {% if error_custom_field[custom_field.custom_field_id] %}
                            <div class="invalid-tooltip">{{ error_custom_field[custom_field.custom_field_id] }}</div>
                          {% endif %}</div>
                      </div>
                    {% endif %}
                    {% if custom_field.type == 'textarea' %}
                      <div class="form-group row custom-field custom-field{{ custom_field.custom_field_id }}" data-sort="{{ custom_field.sort_order }}">
                        <label class="col-sm-2 col-form-label" for="input-custom-field{{ custom_field.custom_field_id }}">{{ custom_field.name }}</label>
                        <div class="col-sm-10">
                          <textarea name="custom_field[{{ custom_field.custom_field_id }}]" rows="5" placeholder="{{ custom_field.name }}" id="input-custom-field{{ custom_field.custom_field_id }}" class="form-control">{{ affiliate_custom_field[custom_field.custom_field_id] ? affiliate_custom_field[custom_field.custom_field_id] : custom_field.value }}</textarea>
                          {% if error_custom_field[custom_field.custom_field_id] %}
                            <div class="invalid-tooltip">{{ error_custom_field[custom_field.custom_field_id] }}</div>
                          {% endif %}</div>
                      </div>
                    {% endif %}
                    {% if custom_field.type == 'file' %}
                      <div class="form-group row custom-field custom-field{{ custom_field.custom_field_id }}" data-sort="{{ custom_field.sort_order }}">
                        <label class="col-sm-2 col-form-label">{{ custom_field.name }}</label>
                        <div class="col-sm-10">
                          <button type="button" id="button-custom-field{{ custom_field.custom_field_id }}" data-loading-text="{{ text_loading }}" class="btn btn-light"><i class="fas fa-upload"></i> {{ button_upload }}</button>
                          <input type="hidden" name="custom_field[{{ custom_field.custom_field_id }}]" value="{{ affiliate_custom_field[custom_field.custom_field_id] ? affiliate_custom_field[custom_field.custom_field_id] }}" id="input-custom-field{{ custom_field.custom_field_id }}"/>
                          {% if error_custom_field[custom_field.custom_field_id] %}
                            <div class="invalid-tooltip">{{ error_custom_field[custom_field.custom_field_id] }}</div>
                          {% endif %}
                        </div>
                      </div>
                    {% endif %}
                    {% if custom_field.type == 'date' %}
                      <div class="form-group row custom-field custom-field{{ custom_field.custom_field_id }}" data-sort="{{ custom_field.sort_order }}">
                        <label class="col-sm-2 col-form-label" for="input-custom-field{{ custom_field.custom_field_id }}">{{ custom_field.name }}</label>
                        <div class="col-sm-10">
                          <div class="input-group date">
                            <input type="text" name="custom_field[{{ custom_field.custom_field_id }}]" value="{{ affiliate_custom_field[custom_field.custom_field_id] ? affiliate_custom_field[custom_field.custom_field_id] : custom_field.value }}" placeholder="{{ custom_field.name }}" id="input-custom-field{{ custom_field.custom_field_id }}" class="form-control"/>
                            <div class="input-group-append">
                              <div class="input-group-text"><i class="fas fa-calendar"></i></div>
                            </div>
                          </div>
                          {% if error_custom_field[custom_field.custom_field_id] %}
                            <div class="invalid-tooltip">{{ error_custom_field[custom_field.custom_field_id] }}</div>
                          {% endif %}
                        </div>
                      </div>
                    {% endif %}
                    {% if custom_field.type == 'time' %}
                      <div class="form-group row custom-field custom-field{{ custom_field.custom_field_id }}" data-sort="{{ custom_field.sort_order }}">
                        <label class="col-sm-2 col-form-label" for="input-custom-field{{ custom_field.custom_field_id }}">{{ custom_field.name }}</label>
                        <div class="col-sm-10">
                          <div class="input-group time">
                            <input type="text" name="custom_field[{{ custom_field.custom_field_id }}]" value="{{ affiliate_custom_field[custom_field.custom_field_id] ? affiliate_custom_field[custom_field.custom_field_id] : custom_field.value }}" placeholder="{{ custom_field.name }}" id="input-custom-field{{ custom_field.custom_field_id }}" class="form-control"/>
                            <div class="input-group-append">
                              <div class="input-group-text"><i class="fas fa-calendar"></i></div>
                            </div>
                          </div>
                          {% if error_custom_field[custom_field.custom_field_id] %}
                            <div class="invalid-tooltip">{{ error_custom_field[custom_field.custom_field_id] }}</div>
                          {% endif %}
                        </div>
                      </div>
                    {% endif %}
                    {% if custom_field.type == 'datetime' %}
                      <div class="form-group row custom-field custom-field{{ custom_field.custom_field_id }}" data-sort="{{ custom_field.sort_order }}">
                        <label class="col-sm-2 col-form-label" for="input-custom-field{{ custom_field.custom_field_id }}">{{ custom_field.name }}</label>
                        <div class="col-sm-10">
                          <div class="input-group datetime">
                            <input type="text" name="custom_field[{{ custom_field.custom_field_id }}]" value="{{ affiliate_custom_field[custom_field.custom_field_id] ? affiliate_custom_field[custom_field.custom_field_id] : custom_field.value }}" placeholder="{{ custom_field.name }}" id="input-custom-field{{ custom_field.custom_field_id }}" class="form-control"/>
                            <div class="input-group-append">
                              <div class="input-group-text"><i class="fas fa-calendar"></i></div>
                            </div>
                          </div>
                          {% if error_custom_field[custom_field.custom_field_id] %}
                            <div class="invalid-tooltip">{{ error_custom_field[custom_field.custom_field_id] }}</div>
                          {% endif %}
                        </div>
                      </div>
                    {% endif %}
                  {% endif %}
                {% endfor %}
              </fieldset>
              <fieldset>
                <legend>{{ text_payment }}</legend>
                <div class="form-group row">
                  <label class="col-sm-2 col-form-label" for="input-tax">{{ entry_tax }}</label>
                  <div class="col-sm-10">
                    <input type="text" name="tax" value="{{ tax }}" placeholder="{{ entry_tax }}" id="input-tax" class="form-control"/>
                  </div>
                </div>
                <div class="form-group row">
                  <label class="col-sm-2 col-form-label">{{ entry_payment }}</label>
                  <div class="col-sm-10">
                    <label class="form-check">{% if payment == 'cheque' %}
                        <input type="radio" name="payment" value="cheque" checked="checked" class="form-check-input"/>
                      {% else %}
                        <input type="radio" name="payment" value="cheque" class="form-check-input"/>
                      {% endif %}
                      {{ text_cheque }}</label> <label class="form-check">{% if payment == 'paypal' %}
                        <input type="radio" name="payment" value="paypal" checked="checked" class="form-check-input"/>
                      {% else %}
                        <input type="radio" name="payment" value="paypal" class="form-check-input"/>
                      {% endif %}
                      {{ text_paypal }}</label> <label class="form-check">{% if payment == 'bank' %}
                        <input type="radio" name="payment" value="bank" checked="checked" class="form-check-input"/>
                      {% else %}
                        <input type="radio" name="payment" value="bank" class="form-check-input"/>
                      {% endif %}
                      {{ text_bank }}</label>
                  </div>
                </div>
                <div id="payment-cheque" class="payment">
                  <div class="form-group row required">
                    <label class="col-sm-2 col-form-label" for="input-cheque">{{ entry_cheque }}</label>
                    <div class="col-sm-10">
                      <input type="text" name="cheque" value="{{ cheque }}" placeholder="{{ entry_cheque }}" id="input-cheque" class="form-control"/>
                      {% if error_cheque %}
                        <div class="invalid-tooltip">{{ error_cheque }}</div>
                      {% endif %}</div>
                  </div>
                </div>
                <div id="payment-paypal" class="payment">
                  <div class="form-group row required">
                    <label class="col-sm-2 col-form-label" for="input-paypal">{{ entry_paypal }}</label>
                    <div class="col-sm-10">
                      <input type="text" name="paypal" value="{{ paypal }}" placeholder="{{ entry_paypal }}" id="input-paypal" class="form-control"/>
                      {% if error_paypal %}
                        <div class="invalid-tooltip">{{ error_paypal }}</div>
                      {% endif %}</div>
                  </div>
                </div>
                <div id="payment-bank" class="payment">
                  <div class="form-group row">
                    <label class="col-sm-2 col-form-label" for="input-bank-name">{{ entry_bank_name }}</label>
                    <div class="col-sm-10">
                      <input type="text" name="bank_name" value="{{ bank_name }}" placeholder="{{ entry_bank_name }}" id="input-bank-name" class="form-control"/>
                    </div>
                  </div>
                  <div class="form-group row">
                    <label class="col-sm-2 col-form-label" for="input-bank-branch-number">{{ entry_bank_branch_number }}</label>
                    <div class="col-sm-10">
                      <input type="text" name="bank_branch_number" value="{{ bank_branch_number }}" placeholder="{{ entry_bank_branch_number }}" id="input-bank-branch-number" class="form-control"/>
                    </div>
                  </div>
                  <div class="form-group row">
                    <label class="col-sm-2 col-form-label" for="input-bank-swift-code">{{ entry_bank_swift_code }}</label>
                    <div class="col-sm-10">
                      <input type="text" name="bank_swift_code" value="{{ bank_swift_code }}" placeholder="{{ entry_bank_swift_code }}" id="input-bank-swift-code" class="form-control"/>
                    </div>
                  </div>
                  <div class="form-group row required">
                    <label class="col-sm-2 col-form-label" for="input-bank-account-name">{{ entry_bank_account_name }}</label>
                    <div class="col-sm-10">
                      <input type="text" name="bank_account_name" value="{{ bank_account_name }}" placeholder="{{ entry_bank_account_name }}" id="input-bank-account-name" class="form-control"/>
                      {% if error_bank_account_name %}
                        <div class="invalid-tooltip">{{ error_bank_account_name }}</div>
                      {% endif %}</div>
                  </div>
                  <div class="form-group row required">
                    <label class="col-sm-2 col-form-label" for="input-bank-account-number">{{ entry_bank_account_number }}</label>
                    <div class="col-sm-10">
                      <input type="text" name="bank_account_number" value="{{ bank_account_number }}" placeholder="{{ entry_bank_account_number }}" id="input-bank-account-number" class="form-control"/>
                      {% if error_bank_account_number %}
                        <div class="invalid-tooltip">{{ error_bank_account_number }}</div>
                      {% endif %}</div>
                  </div>
                </div>
              </fieldset>
              <fieldset>
                <legend>{{ text_other }}</legend>
                <div class="form-group row">
                  <label class="col-sm-2 col-form-label" for="input-status">{{ entry_status }}</label>
                  <div class="col-sm-10">
                    <select name="status" id="input-status" class="form-control">
                      {% if status %}
                        <option value="1" selected="selected">{{ text_enabled }}</option>
                        <option value="0">{{ text_disabled }}</option>
                      {% else %}
                        <option value="1">{{ text_enabled }}</option>
                        <option value="0" selected="selected">{{ text_disabled }}</option>
                      {% endif %}
                    </select>
                  </div>
                </div>
              </fieldset>
            </div>
            {% if customer_id %}
              <div class="tab-pane" id="tab-history">
                <fieldset>
                  <legend>{{ text_history }}</legend>
                  <div id="history"></div>
                </fieldset>
                <br/>
                <fieldset>
                  <legend>{{ text_history_add }}</legend>
                  <div class="form-group row">
                    <label class="col-sm-2 col-form-label" for="input-comment">{{ entry_comment }}</label>
                    <div class="col-sm-10">
                      <textarea name="comment" rows="8" placeholder="{{ entry_comment }}" id="input-comment" class="form-control"></textarea>
                    </div>
                  </div>
                </fieldset>
                <div class="text-right">
                  <button id="button-history" data-loading-text="{{ text_loading }}" class="btn btn-primary"><i class="fas fa-plus-circle"></i> {{ button_history_add }}</button>
                </div>
              </div>
              <div class="tab-pane" id="tab-transaction">
                <fieldset>
                  <legend>{{ text_transaction }}</legend>
                  <div id="transaction"></div>
                </fieldset>
                <br/>
                <fieldset>
                  <legend>{{ text_transaction_add }}</legend>
                  <div class="form-group row">
                    <label class="col-sm-2 col-form-label" for="input-description">{{ entry_description }}</label>
                    <div class="col-sm-10">
                      <input type="text" name="description" value="" placeholder="{{ entry_description }}" id="input-description" class="form-control"/>
                    </div>
                  </div>
                  <div class="form-group row">
                    <label class="col-sm-2 col-form-label" for="input-amount">{{ entry_amount }}</label>
                    <div class="col-sm-10">
                      <input type="text" name="amount" value="" placeholder="{{ entry_amount }}" id="input-amount" class="form-control"/>
                    </div>
                  </div>
                </fieldset>
                <div class="text-right">
                  <button type="button" id="button-transaction" data-loading-text="{{ text_loading }}" class="btn btn-primary"><i class="fas fa-plus-circle"></i> {{ button_transaction_add }}</button>
                </div>
              </div>
              <div class="tab-pane" id="tab-report">
                <fieldset>
                  <legend>{{ text_report }}</legend>
                  <div id="report"></div>
                </fieldset>
              </div>
            {% endif %}
          </div>
        </form>
      </div>
    </div>
  </div>
</div>
<script type="text/javascript"><!--
$('input[name=\'customer\']').autocomplete({
	'source': function(request, response) {
		$.ajax({
			url: 'index.php?route=customer/customer/autocomplete&user_token={{ user_token }}&filter_name=' + encodeURIComponent(request),
			dataType: 'json',
			success: function(json) {
				response($.map(json, function(item) {
					return {
						category: item['customer_group'],
						label: item['name'],
						value: item['customer_id'],
						customer_group_id: item['customer_group_id'],
					}
				}));
			}
		});
	},
	'select': function(item) {
		$('input[name=\'customer\']').val(item['label']);
		$('input[name=\'customer_id\']').val(item['value']);
		$('input[name=\'customer_group_id\']').val(item['customer_group_id']);

		$('input[name=\'customer_group_id\']').trigger('change');
	}
});
//--></script>
<script type="text/javascript"><!--
$('input[name=\'customer_group_id\']').on('change', function() {
	$.ajax({
		url: 'index.php?route=customer/customer/customfield&user_token={{ user_token }}&customer_group_id=' + this.value,
		dataType: 'json',
		success: function(json) {
			$('.custom-field').hide();
			$('.custom-field').removeClass('required');

			for (i = 0; i < json.length; i++) {
				custom_field = json[i];

				$('.custom-field' + custom_field['custom_field_id']).show();

				if (custom_field['required']) {
					$('.custom-field' + custom_field['custom_field_id']).addClass('required');
				}
			}
		},
		error: function(xhr, ajaxOptions, thrownError) {
			alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
		}
	});
});

$('input[name=\'customer_group_id\']').trigger('change');
//--></script>
<script type="text/javascript"><!--
$('#history').on('click', '.pagination a', function(e) {
	e.preventDefault();

	$('#history').load(this.href);
});

$('#history').load('index.php?route=customer/customer/history&user_token={{ user_token }}&customer_id={{ customer_id }}');

$('#button-history').on('click', function(e) {
	e.preventDefault();

	$.ajax({
		url: 'index.php?route=customer/customer/addhistory&user_token={{ user_token }}&customer_id={{ customer_id }}',
		type: 'post',
		dataType: 'json',
		data: 'comment=' + encodeURIComponent($('#tab-history textarea[name=\'comment\']').val()),
		beforeSend: function() {
			$('#button-history').button('loading');
		},
		complete: function() {
			$('#button-history').button('reset');
		},
		success: function(json) {
			$('.alert-dismissible').remove();

			if (json['error']) {
				$('#tab-history').prepend('<div class="alert alert-danger alert-dismissible"><i class="fas fa-exclamation-circle"></i> ' + json['error'] + ' <button type="button" class="close" data-dismiss="alert">&times;</button></div>');
			}

			if (json['success']) {
				$('#tab-history').prepend('<div class="alert alert-success alert-dismissible"><i class="fas fa-check-circle"></i> ' + json['success'] + ' <button type="button" class="close" data-dismiss="alert">&times;</button></div>');

				$('#history').load('index.php?route=customer/customer/history&user_token={{ user_token }}&customer_id={{ customer_id }}');

				$('#tab-history textarea[name=\'comment\']').val('');
			}
		},
		error: function(xhr, ajaxOptions, thrownError) {
			alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
		}
	});
});
//--></script>
<script type="text/javascript"><!--
$('#transaction').on('click', '.pagination a', function(e) {
	e.preventDefault();

	$('#transaction').load(this.href);
});

$('#transaction').load('index.php?route=customer/customer/transaction&user_token={{ user_token }}&customer_id={{ customer_id }}');

$('#button-transaction').on('click', function(e) {
	e.preventDefault();

	$.ajax({
		url: 'index.php?route=customer/customer/addtransaction&user_token={{ user_token }}&customer_id={{ customer_id }}',
		type: 'post',
		dataType: 'json',
		data: 'description=' + encodeURIComponent($('#tab-transaction input[name=\'description\']').val()) + '&amount=' + encodeURIComponent($('#tab-transaction input[name=\'amount\']').val()),
		beforeSend: function() {
			$('#button-transaction').button('loading');
		},
		complete: function() {
			$('#button-transaction').button('reset');
		},
		success: function(json) {
			$('.alert-dismissible').remove();

			if (json['error']) {
				$('#tab-transaction').prepend('<div class="alert alert-danger alert-dismissible"><i class="fas fa-exclamation-circle"></i> ' + json['error'] + ' <button type="button" class="close" data-dismiss="alert">&times;</button></div>');
			}

			if (json['success']) {
				$('#tab-transaction').prepend('<div class="alert alert-success alert-dismissible"><i class="fas fa-check-circle"></i> ' + json['success'] + ' <button type="button" class="close" data-dismiss="alert">&times;</button></div>');

				$('#transaction').load('index.php?route=customer/customer/transaction&user_token={{ user_token }}&customer_id={{ customer_id }}');

				$('#tab-transaction input[name=\'amount\']').val('');
				$('#tab-transaction input[name=\'description\']').val('');
			}
		},
		error: function(xhr, ajaxOptions, thrownError) {
			alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
		}
	});
});
//--></script>
<script type="text/javascript"><!--
$('#report').on('click', '.pagination a', function(e) {
	e.preventDefault();

	$('#report').load(this.href);
});

$('#report').load('index.php?route=marketing/affiliate/report&user_token={{ user_token }}&customer_id={{ customer_id }}');
//--></script>
<script type="text/javascript"><!--
$('#content').on('click', 'button[id^=\'button-custom-field\'], button[id^=\'button-address\']', function() {
	var element = this;

	$('#form-upload').remove();

	$('body').prepend('<form enctype="multipart/form-data" id="form-upload" style="display: none;"><input type="file" name="file" /></form>');

	$('#form-upload input[name=\'file\']').trigger('click');

	if (typeof timer != 'undefined') {
		clearInterval(timer);
	}

	timer = setInterval(function() {
		if ($('#form-upload input[name=\'file\']').val() != '') {
			clearInterval(timer);

			$.ajax({
				url: 'index.php?route=tool/upload/upload&user_token={{ user_token }}',
				type: 'post',
				dataType: 'json',
				data: new FormData($('#form-upload')[0]),
				cache: false,
				contentType: false,
				processData: false,
				beforeSend: function() {
					$(element).button('loading');
				},
				complete: function() {
					$(element).button('reset');
				},
				success: function(json) {
					$(element).parent().find('.invalid-tooltip').remove();

					if (json['error']) {
						$(element).parent().find('input[type=\'hidden\']').after('<div class="invalid-tooltip">' + json['error'] + '</div>');
					}

					if (json['success']) {
						alert(json['success']);
					}

					if (json['code']) {
						$(element).parent().find('input[type=\'hidden\']').val(json['code']);
					}
				},
				error: function(xhr, ajaxOptions, thrownError) {
					alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
				}
			});
		}
	}, 500);
});

$('.date').datetimepicker({
	'format': 'YYYY-MM-DD',
	'locale': '{{ datepicker }}',
	'allowInputToggle': true
});

$('.time').datetimepicker({
	'format': 'HH:mm',
	'locale': '{{ datepicker }}',
	'allowInputToggle': true
});

$('.datetime').datetimepicker({
	'format': 'YYYY-MM-DD HH:mm',
	'locale': '{{ datepicker }}',
	'allowInputToggle': true
});

$('#tab-general .form-group[data-sort]').detach().each(function() {
	if ($(this).attr('data-sort') >= 0 && $(this).attr('data-sort') <= $('#tab-general .form-group').length) {
		$('#tab-general .form-group').eq($(this).attr('data-sort')).before(this);
	}

	if ($(this).attr('data-sort') > $('#tab-general .form-group').length) {
		$('#tab-general .form-group:last').after(this);
	}

	if ($(this).attr('data-sort') < -$('#tab-general .form-group').length) {
		$('#tab-general .form-group:first').before(this);
	}
});
//--></script>
<script type="text/javascript"><!--
$('input[name=\'payment\']').on('change', function() {
	$('.payment').hide();

	$('#payment-' + this.value).show();
});

$('input[name=\'payment\']:checked').trigger('change');
//--></script>
{{ footer }}